<div class="form">   

    <?php $this->render('cmswidgets.views.notification'); ?>
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'currency-form',
        'enableAjaxValidation' => true,
    ));
    ?>

    <?php echo $form->errorSummary($model); ?>
    <div>   
        <div class="left">
            <div class="row">
                <?php echo $form->labelEx($model, 'codeTo'); ?>
                <?php
                $sql = "SELECT currencyCode FROM gxc_countries "
                        . "WHERE currencyCode!='USD' and currencyCode!='' "
                        . "and  currencyCode != ALL(SELECT codeTo FROM gxc_currency)"
                        . " order by currencyCode ASC";
                $lData = CHtml::listData(Yii::app()->db->createCommand($sql)->queryAll(), 'currencyCode', 'currencyCode');
                echo $form->dropDownList($model, 'codeTo', $lData, array('id' => 'codeTo'));
                ?>
                <?php echo $form->error($model, 'code'); ?>
            </div>
            <div class="row">
                <?php echo $form->labelEx($model, 'conversionRate'); ?>
                <?php echo $form->textField($model, 'conversionRate', array('id' => 'conversionRate')); ?>
                <?php echo $form->error($model, 'conversionRate'); ?>
            </div>
        </div>
        <div class="clear"></div>
    </div>    

    <div class="row">
        <?php echo CHtml::submitButton(t('cms', 'Save'), array('class' => 'bebutton active')); ?>
    </div>

    <?php $this->endWidget(); ?>
</div><!-- form -->

<script>
    $(document).ready(function() {

        var codeto = document.getElementById("codeTo").value;
        $.get('<?php echo SITE_PATH; ?>shopping/loadcurrency/codeto/"' + codeto + '"', function(data) {
            $('input#conversionRate').val(data);
        });

        $("#codeTo").change(function() {
            var codeto = $(this).val();
            //$("#conversionRate").remove();
            $.get('<?php echo SITE_PATH; ?>shopping/loadcurrency/codeto/"' + codeto + '"', function(data) {
                $('input#conversionRate').val(data);
            });
        });
    });
</script>


